{extend name="common/index"}
{block name="css"}
<style>
    #editForm label {
        padding: 0px 15px;
    }
</style>
{/block}
{block name="content"}
<div class="layui-row">
    <form id="searchForm" class="layui-form layui-form-pane tpl-form-search" onkeydown="if(event.keyCode=='13'){reloadTable('#searchForm');return false;}">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-inline">
                    <select name="type">
                        <option value="">请选择</option>
                        {volist name="typeList" id="vo"}
                        <option value="{$key}">{$vo}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">发送时间</label>
                <div class="layui-input-inline">
                    <select name="is_read">
                        <option value="">请选择</option>
                        <option value="0">未读</option>
                        <option value="1">已读</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-normal" onclick="reloadTable('#searchForm');">搜索</a>
                    <a class="layui-btn" href="{:url('edit')}">新增</a>
                </div>
            </div>
        </div>
    </form>
</div>
<!--数据列表-->
<div class="layui-btn-group">
    <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="ajaxDelete(getSelectedIdList(), '{:url("Message/delete")}');">
    <i class="layui-icon layui-icon-delete"></i>删除选中
    </button>
</div>
<table id="msgTable" lay-filter="msgTable"></table>

<script type="text/html" id="operating">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    </div>
</script>

{/block}

{block name="script"}
<script type="text/javascript">
    var table;
    layui.use(['form', 'table'], function () {
        table = layui.table;
        var user_id = {:session('userInfo.user_id')};

        //表格数据渲染：公告
        tableIns = table.render({
            elem: '#msgTable'
            , url: '{:url("getSentDataList")}'
            , page: true
            ,limit: table_limit
            ,limits: table_limits
            , cols: [[
                {type: 'checkbox', width: 50}
                , {field: 'type_text', title: '类型', width: 100}
                , {field: 'title', title: '标题', width: '30%'}
                , {field: 'content', title: '详细内容', width: '15%'}
                , {field: 'create_time', title: '发送时间', minWidth: 150}
                ,{title:'操作', toolbar: '#operating', align:'center', width: 100}
            ]]
            ,where: getFormJson('#searchForm')
        });

        //监听工具条
        table.on('tool(msgTable)', function(obj){
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('接收者消息也将被删除，确定继续吗？', function(index){
                    $.post('{:url("delete")}',{id:data.id}, function (result) {
                        layer.close(index);
                        if (result.code) {
                            layer.msg(result.msg);
                            reloadTable('#searchForm');
                        } else {
                            layer.alert(result.msg, {icon:2});
                        }
                    }, 'json');
                });
            } else if (obj.event === 'edit') {
                window.location.href = 'edit?id='+data.id;
            }
        });
    });

    //获取当前选中的id，数组
    function getSelectedIdList() {
        var checkList = table.checkStatus('msgTable');
        var id_list = [];
        if (checkList.data.length>0) {
            $.each(checkList.data, function (key, val) {
                id_list[key] = val.id;
            });
        }
        return id_list;
    }
</script>
{/block}